<template>
  <div id="app">
    <transition :name="transitionName">
      <keep-alive v-if="$route.meta.keepAlive">
        <router-view class="router"></router-view>
      </keep-alive>
      <router-view class="router" v-else></router-view>
    </transition>
  </div>
</template>
<script>
import defaultSetting from "./settings";
import { Toast } from "vant";
import qs from 'qs'
export default {
  name: "app",
  computed: {
    transitionName() {
      if (defaultSetting.needPageTrans) {
        return this.$store.state.direction;
      }
      return "";
    },
  },
  created() {
    if (process.env.VUE_APP_BUILDENV == "yzj") {
      try {
        let arr = location.href.split("?")[1].split("#")[0].split("&");
        let obj = {};
        arr.forEach((e) => {
          let e1 = e.split("=");
          obj[e1[0]] = e1[1];
        });
        console.log(obj);
        sessionStorage.setItem("ticket", obj.ticket);
        if (this.$route.query.ticket) {
          sessionStorage.setItem("ticket", this.$route.query.ticket);
        }
      } catch (error) {
        Toast.fail("获取ticket失败");
      }
    } else {
      try {
        let obj = qs.parse(window.location.href.split("?")[1].split("#")[0]);
        console.log(obj);
        sessionStorage.setItem("ticket", obj.code);
        if (this.$route.query.code) {
          sessionStorage.setItem("ticket", this.$route.query.code);
        }
      } catch (error) {
        Toast.fail("获取code失败");
      }
    }
  },
};
</script>

<style lang="scss">
#app {
  font-family: "Avenir", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
  width: 100%;
  height: 100%;
  position: relative;
}

.router {
  width: 100%;
  height: 100%;
  position: absolute;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  // background-color: #fff;
}
</style>
